<?php
    $page=isset($_GET['page'])?$_GET['page'] : 1;
    $size=isset($_GET['size'])?$_GET['size'] : 3;

    $dbh = new PDO('mysql:host=127.0.0.1;dbname=1705phpa', 'root','root');
    $sql="select * from week3";
    $res=$dbh->query($sql);

    $count_num=$res->rowCount();//总条数
    $page_count=ceil($count_num/$size);//当前页数
    $limit=($page-1)*$size;//计算偏移量
    $prev=$page-1>1 ? $page-1 : 1;//上一页
    $next=$page+1< $page_count ? $page+1 : $page_count;//下一页
    $sql2="select * from week3 limit $limit,$size";
    $data=$dbh->query($sql2);
    $relsd=$data->fetchAll(2);

    if(!$relsd)
    {
        $arr['code']=1;
        $arr['msg']='失败';
        $arr['data']=[];

        echo json_encode($arr);
    }
    $arr['code']=0;
    $arr['msg']="成功";
    $arr['data']=$relsd;
    $arr['num']=$page_count;

    echo json_encode($arr);


?>